from typing import TYPE_CHECKING

import pygame

from vengine.ve_coord import Point2d
from vengine.ve_data import VE_HashMapStorage

if TYPE_CHECKING:
    from vengine.ve_group import VE_Group
    from vengine.ve_objects import VE_Object


# Object storing & querying
VE_ObjectIdPool: dict[str, "VE_Object"] = {}

def has_object(object_id: str) -> bool:
    """ Test if object with id object_id exists """
    return object_id in VE_ObjectIdPool
    
def get_object(object_id: str) -> "VE_Object":
    """ Get object by id, if object doesn't exist, return None """
    return VE_ObjectIdPool.get(object_id) # type: ignore

# Group storing & querying
VE_GroupIdPool: dict[str, "VE_Group"] = {}

def has_group(group_id: str) -> bool:
    """ Test if group with id group_id exists """
    return group_id in VE_GroupIdPool

def get_group(group_id: str) -> "VE_Group":
    """ Get group by id, if group doesn't exist, return None """
    return VE_GroupIdPool.get(group_id) # type: ignore


VE_DATA_STORAGE = VE_HashMapStorage()

# True if application.init() is called
VE_DATA_STORAGE["is_initialized"] = False

# Pygame stuff, value is dynamically set in init state
VE_DATA_STORAGE["window"] = None
def get_window() -> pygame.Surface: return VE_DATA_STORAGE["window"]

VE_DATA_STORAGE["clock"] = None
def get_clock() -> pygame.time.Clock: return VE_DATA_STORAGE["clock"]


# Keyboard & Mouse state, value is dynamically updated in tick loop
KMstate = VE_HashMapStorage()

def get_mouse_pos() -> Point2d: return Point2d(pygame.mouse.get_pos())